package com.dingding.gmall.order.controller;

import com.dingding.gmall.order.entity.OrderEntity;
import com.dingding.gmall.order.entity.OrderReturnReasonEntity;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.Date;
import java.util.UUID;

/**
 * @author liugongding
 * @description:
 * @date 2022/2/23 10:40 PM
 */

//@RestController
    @Controller
@RequestMapping("")
public class RabbitMqTestController {

    @Autowired
    private RabbitTemplate rabbitTemplate;

    @GetMapping("sendMsg")
    public String sendMsg(){
        for (long i=0;i<10;i++){
            if ((i&2) ==0) {
                OrderReturnReasonEntity reasonEntity = new OrderReturnReasonEntity();
                reasonEntity.setId(i);
                reasonEntity.setCreateTime(new Date());
                reasonEntity.setName("reason");
                reasonEntity.setStatus(1);
                reasonEntity.setSort(2);
                String msg = "hello world";
                rabbitTemplate.convertAndSend("hello-java-exchange", "hello-java-routingKey", reasonEntity);
            } else {
                OrderEntity entity = new OrderEntity();
                entity.setOrderSn(UUID.randomUUID().toString());
                rabbitTemplate.convertAndSend("hello-java-exchange", "hello-java-routingKey", entity);

            }
        }
        return "ok";
    }

    @GetMapping("/{page}.html")
    public String page(@PathVariable("page")String page){
        return page;
    }
}
